<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
    <title>分拣区管理-入库</title>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/plugin/layui/css/layui.css" media="all" />
    <script type="text/javascript" src="/static/plugin/jquery/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="/static/plugin/layui/layui.js"></script>
    <script type="text/javascript" src="/static/js/base.js"></script>
<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>分拣区管理-入库</cite>
        </a>
      </span>
</div>
<div class="x-body">

    <div class="layui-row" style="margin-bottom: 18px">
        <div class="layui-form">
            <div class="layui-input-inline">

                <div class="layui-input-inline" style="width: 150px">
                    <input class="layui-input" id="keyword01" placeholder="请输入姓名" style="width: 150px">
                </div>
                <button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
            </div>
        </div>
    </div>

    <xblock>
<!--        <button class="layui-btn layui-btn-warm" id="add"><i class="layui-icon layui-icon-add-circle-fine"></i>新增</button>-->
        <!--<button class="layui-btn layui-btn-danger" id="del"><i class="layui-icon layui-icon-delete"></i>批量删除</button>-->
    </xblock>
    <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
    <table class="layui-hide" id="tableDetails" lay-filter="tableDetails"></table>
</div>
<div id="addDivID" style="display:none">
    <form class="layui-form" id="addFormID" style="margin-top:20px">
        <div style="width:100%;height:250px;overflow: auto;">
            <div style="margin-top: 10px"></div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span><span>车辆牌号</span>
                </label>
                <div class="layui-input-inline"  style = "width:280px;">
                    <select lay-filter="vehicleId" name="vehicleId" lay-verify="required">
                        <option value=""></option>
                        <option th:each="car:${carList}" th:value="${car.cid}" th:text="${car.cplate}"></option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span><span>司机姓名</span>
                </label>
                <div class="layui-input-inline"  style = "width:280px;">
                    <select lay-filter="driverId" name="driverId" lay-verify="required">
                        <option value=""></option>
                        <option th:each="driver:${driverList}" th:value="${driver.did}" th:text="${driver.dname}"></option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span><span>接收人员</span>
                </label>
                <div class="layui-input-inline"  style = "width:280px;">
                    <select lay-filter="receiveBy" name="receiveBy" lay-verify="required">
                        <option value=""></option>
                        <option th:each="user:${userList}" th:value="${user.userId}" th:text="${user.realName}"></option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="subBtn" lay-submit lay-filter="addForm">添加</button>
                <button  class="layui-btn layui-btn-primary">取消</button>
            </div>
        </div>

    </form>
</div>


<div id="updateDivID" style="display:none">
    <form class="layui-form" id="updateFormID" style="margin-top:20px">
        <div style="width:100%">
            <div style="margin-top: 10px"></div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="updateSubBtn" lay-submit lay-filter="updateForm">更新</button>
                <button  class="layui-btn layui-btn-primary">取消</button>
            </div>
        </div>
    </form>
</div>

<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    var treeObj;
    var treeObj2;

    function createTime(v){
        var date = new Date(v);
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        m = m<10?'0'+m:m;
        var d = date.getDate();
        d = d<10?("0"+d):d;
        var h = date.getHours();
        h = h<10?("0"+h):h;
        var M = date.getMinutes();
        M = M<10?("0"+M):M;
        var str = y+"-"+m+"-"+d+" "+h+":"+M;
        return str;
    }

    $(document).ready(function () {
        var time = new Date();
        var day = ("0" + time.getDate()).slice(-2);
        var month = ("0" + (time.getMonth() + 1)).slice(-2);
        var today = time.getFullYear() + "-" + (month);
        $('#dateTime').val(today);
    })

    layui.use(['table','layer','upload','form','laydate'], function(){
        var table = layui.table;
        var form=layui.form;
        var laydate = layui.laydate;
        var formSelects = layui.formSelects;
        laydate.render({
            elem: '#date1',
            value:new Date()
        });
        laydate.render({
            elem: '#date2'
        });

        laydate.render({
            elem: '#date3',
            type: 'month',
            value: new Date(),
            done:function(value, date, endDate) {
                $('#dateTime').val(value);
            }
        });

        var $ = layui.jquery, active = {
            reload:function () {
                table.reload('contentTable',{
                    method:'get'
                    ,where:{
                        'realName':$('#keyword01').val()
                    }
                    ,page: {
                        curr: 1//重新从第 1 页开始
                    }
                });
            }
        }

        table.render({
            elem: '#tableList'
            ,id:'contentTable'
            ,url: '/warehousing/queryWarehousingPage'
            ,where:{
                'logOn':'1'
            }
            , cols: [
                [{field:'uid', title:'序号',width: 60, type:'numbers',align:'center'}
                , {field: 'cplate', title: '车辆牌号', width: '25%', sort: true}
                , {field: 'dname', title: '司机姓名', width: '25%', sort: true}
                , {field: 'realName', title: '接收人员', width: '25%', sort: true}
                , {field: 'createDate', title: '创建时间', width: '20%',templet:function (row) {
                        return createTime(row.createDate);
                    }}
                ]
            ]
            , page: true
            ,totalRow: true
            ,done : function(res, curr, count){
                $('th').css({
                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
                })
            }
        });

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.layui-col-md12 .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.select .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听行单击事件（双击事件为：rowDouble）
        table.on('row(tableList)', function(obj){
            var data = obj.data;
            table.render({
                elem: '#tableDetails'
                ,url:'/sortReceivingDetail/queryWarehousingDetailPage'
                ,where:{
                    'receivingId':data.receivingId
                }
                ,toolbar: '#toolbar'
                ,title: '明细表'
                ,id :'contenttableDetails'
                ,limits:[10,20,30]
                ,cols: [
                    [
                        {type: 'checkbox',fixed: 'left'},
                        {field:'id', title:'序号', width: 50,type:'numbers', align:'center'},
                        {field:'containerNumber', title:'货框编号', edit: 'containerNumber', align:'center'},
                        {field:'containerId', title:'容器ID', align:'center', hide:true},
                        {field:'oldQuantity', title:'发货数量', edit: 'text', align:'center'},
                        {field:'quantity', title:'收货数量', edit: 'text', align:'center'}
                       /* {field:'sprayingRequirements', title:'喷涂要求', edit: 'text', align:'center'},
                        {field:'emergencyLevel', title:'紧急程度', edit: 'text', align:'center'}*/
                    ]
                ]
                ,page: true
                ,done : function(){
                    $('th').css({
                        'background-color': '#009688', 'color': '#fff','font-weight':'bold'
                    })
                }
            });
        });


        table.render({
            elem: '#tableDetails02'
            ,url:'/static/json/jyy/list3.json'
            ,toolbar: '#toolbar'
            ,title: '明细表'
            ,id :'contenttableDetails02'
            ,limits:[10,20,30]
            ,cols: [
                [
                    {type: 'checkbox',fixed: 'left'},
                    {field:'id', title:'序号', width: 50,type:'numbers', align:'center'},
                    {field:'mid', title:'物料id', align:'center', hide:true},
                    {field:'customer',title: '供应商',align:'center'},
                    {field:'productNumber', title:'图号', align:'center'},
                    {field:'num', title:'发货数量', width: 120, edit: 'text', align:'center'},
                    {field:'num', title:'收货数量', width: 120, edit: 'text', align:'center'},
                    {field:'frameType', title:'货框型号', edit: 'text', align:'center'},
                    {field:'frameType', title:'货框编号', edit: 'text', align:'center'},
                    {field:'num', title:'每框数量', width: 120, edit: 'text', align:'center'},
                    {field:'asks', title:'喷涂要求', edit: 'text', align:'center'},
                    {field:'times', title:'时间', edit: 'text', align:'center'},
                    {field:'level', title:'紧急程度', edit: 'text', align:'center'}
                ]
            ]
            ,page: true
            ,done : function(){
                $('th').css({
                    'background-color': '#009688', 'color': '#fff','font-weight':'bold'
                })
            }
        });


        //监听工具条
        table.on('tool(tableList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                //detail('编辑角色', 'showUpdateStaff?id=' + data.postId, 600, 350);
            } else if (obj.event === 'del') {
                layer.confirm('确定是否删除？', {
                    btn: ['确定','取消'] //按钮
                }, function(index){
                    del(data.receivingId)
                })

            } else if (obj.event === 'edit') {
                update('编辑员工', 'showUpdateStaff?userId=' + data.userId, 540, 520);
            }
        });

         /**
          * 删除
          *
          * */
        function del(receivingId) {
             $.ajax({
                 type: 'get',
                 url: '/warehousing/delete',
                 data:{'receivingId':receivingId},
                 success: function (data) {
                     if (data) {
                         layer.msg('删除成功',{icon: 1})
                     }else {
                         layer.msg("删除失败！", {icon: 2});
                     }
                     setTimeout(function(){
                         window.location.reload()
                     },1000);
                 }
             })
        }

        /**
         * 修改
         *
         * */
        function update(title, url, w, h) {
            if (title == null || title == '') {
                title = false;
            }
            if (url == null || url == '') {
                url = "/error/404";
            }
            if (w == null || w == '') {
                w = ($(window).width() * 0.9);
            }
            if (h == null || h == '') {
                h = ($(window).height() - 50);
            }
            layer.open({
                id: 'user-update',
                type: 1,
                area: [w + 'px', h + 'px'],
                maxmin: true,
                anim: 1,
                shade: 0.4,
                title: title,
                /***
                 * [{field:'uid', title:'序号',width: 60, type:'numbers',align:'center'}
                 , {field: 'jobNumber', title: '工号', width: '10%', sort: true}
                 , {field: 'realName', title: '姓名', width: '10%', sort: true}
                 , {field: 'sex', title: '性别', width: '10%', sort: true}
                 , {field: 'deptName', title: '部门', width: '10%', sort: true}
                 , {field: 'phoneNumber', title: '手机', width: '15%', sort: true}
                 , {field: 'email', title: '邮箱', width: '13%', sort: true}
                 , {field: 'createDate', title: '创建时间', width: '15%',templet:function (row) {
                        return createTime(row.createDate);
                    }}
                 , {field: 'remark', title: '操作', width: '10%', toolbar: "#toolBar"}
                 ]
                 */
                content: $('#updateDivID'),
                success: function(){
                    form.render();
                    $.ajax({
                        type:'get',
                        url:url,
                        success:function (data) {
                            var sysUser = JSON.parse(data);
                            //员工ID
                            $('input[name="userId"]').val(sysUser.userId);

                            //员工编号
                            $('input[name="jobNumber"]').val(sysUser.jobNumber);
                            //姓名
                            $('input[name="realName"]').val(sysUser.realName);
                            //性别

                            console.log(sysUser.sex.localeCompare("女") == 1)

                            if (sysUser.sex.localeCompare("女") == 1) {
                                $("#testRadio01").removeAttr("checked");
                                $("#testRadio02").attr("checked", "checked");

                            }else {
                                $("#testRadio02").removeAttr("checked");
                                $("#testRadio01").attr("checked", "checked");
                            }
                            //部门deptId

                            var sysDept = sysUser.sysDeptList;
                            $('#deptSelect').empty();
                            for (var i = 0 ; i < sysDept.length ; i ++){
                                if (sysUser.deptId == sysDept[i].deptId) {
                                    $('#deptSelect').append('<option value="'+sysDept[i].deptId+'" selected>'+sysDept[i].deptName+'</option>');// 下拉菜单里添加元素

                                }else {
                                    $('#deptSelect').append('<option value="'+sysDept[i].deptId+'">'+sysDept[i].deptName+'</option>');// 下拉菜单里添加元素

                                }
                            }
                            form.render('select');//需要渲染一下



                            //岗位
                            var sysPosition = sysUser.sysPositionList;

                            var str = []

                            var init = []

                            for (var j = 0 ; j < sysPosition.length ; j ++){
                                var obj = {'name':sysPosition[j].postName,'val':sysPosition[j].postId,'selected':true}
                                str.push(obj);
                                init.push(sysPosition[j].selected)
                            }

                            console.log(str)

                            //local模式
                            formSelects.render({
                                name: 'postUpdate',
                                init: init,
                                data: {//自定义渲染数据
                                    arr: str
                                }
                            });

                            //手机号码
                            $('input[name="phoneNumber"]').val(sysUser.phoneNumber);
                            //邮箱
                            $('input[name="email"]').val(sysUser.email);

                            form.render(); //更新全部

                        }
                    })
                }
            });
        }

        function detail(title, url, w, h) {
            var number = 1;
            if (title == null || title == '') {
                title = false;
            }
            ;
            if (url == null || url == '') {
                url = "/error/404";
            }
            ;
            if (w == null || w == '') {
                w = ($(window).width() * 0.9);
            }
            ;
            if (h == null || h == '') {
                h = ($(window).height() - 50);
            }
            ;
            layer.open({
                id: 'user-detail',
                type: 1,
                area: [w + 'px', h + 'px'],
                maxmin: true,
                shade: 0.4,
                anim: 1,
                title: title,
                //content: url + '&detail=true',
                // btn:['关闭']
                content: $('#updateDivID'),
                success: function(){
                    form.render();
                    $.ajax({
                        type:'get',
                        url:url,
                        success:function (data) {
                            var postData = JSON.parse(data);
                            $('input[name="postName"]').val(postData.postName);
                            $('input[name="remark"]').val(postData.remark);
                            $('input[name="postId"]').val(postData.postId);

                        }
                    })
                }
            });
        }

        $("#add").click(function(){
            $("#brand1").hide()
            $("#brand2").hide()

            layer.open({
                type: 1 ,				//Page层类型
                area: ['440px', '380px'] 	//宽  高
                ,title: '新增'
                ,shade: 0.6 			//遮罩透明度
                ,maxmin: true 			//允许全屏最小化
                ,anim: 1 				//0-6的动画形式，-1不开启
                ,content: $('#addDivID')
                ,success: function(){
                    //员工编号
                    $('input[name="jobNumber"]').val('');
                    //姓名
                    $('input[name="realName"]').val('');
                    //手机号码
                    $('input[name="phoneNumber"]').val('');
                    //邮箱
                    $('input[name="email"]').val('');

                    form.render(); //更新全部
                    form.render();
                }
            });
        });

        //批量删除
        $("#del").click(function(){
            var rowData = table.checkStatus('contentTable');
            var data = rowData.data;
            var idArr = new Array();
            if(data.length == 0){

                layer.alert("请至少选择一条记录！",{icon :5})

            } else {
                for(var i=0;i < data.length;i++){
                    idArr[i] = data[i].wareHouseId;
                }
                $.ajax({
                    type:'post',
                    url:'/wareHouse/delete',
                    data:{"idArr" : idArr},
                    success:function(data){
                        layer.confirm('确定删除吗？', function(){
                            if(data > 0){
                                layer.msg('删除成功',{icon:6})
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                                setTimeout(function(){
                                    window.location.reload();
                                },2000);
                            }else{
                                layer.msg('删除失败',{icon:5})
                                location.reload();
                            }
                        });
                    }
                });
            }
        });

        form.verify({
            jobNumber:function (value, item) {
                if(value.trim() == ''){
                    return '员工编号不能为空';
                }
            },
            realName:function (value, item) {
                if(value.trim() == ''){
                    return '姓名不能为空';
                }
            },
            phoneNumber:function (value, item) {
                if(value.trim() == ''){
                    return '手机号码不能为空';
                }
            },
            deptId:function (value,item) {
                if(value.trim() == ''){
                    return '归属部门不能为空';
                }
            }
        })
        /**  data:{itemName:"12",startDate:'2019-09-20'},
         * 通用表单提交(AJAX方式),totalMoney:100,startDate:'2019-09-20',dueDate:'2019-09-20'
         */
        form.on('submit(addForm)', function () {
            $("#subBtn").attr("disabled",true);
                $.ajax({
                    type:'post',
                    url:'/warehousing/add',
                    data:$('#addFormID').serialize(),
                    cache:false,
                }).done(
                    function(res) {
                        if (res) {
                            layer.msg('新增成功',{icon:6})
                            setTimeout(function(){
                                location.reload();
                            },1000);
                        }
                    }
                ).fail(
                    function() {
                    layer.msg('新增失败',{icon:5})
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        })
        form.on('submit(updateForm)', function () {
            var post =formSelects.value('postUpdate', 'val');     //[10, 111]
            var postId = [];
            for (var i = 0; i < post.length; i++) {
                if (post[i] == null) {
                    continue ;
                }
                postId.push(post[i]);
            }
            if(post.length == 0){
                layer.msg("岗位不能为空",{icon:5})
                return false;
            }
            var data = $.param({'postId':postId}) + '&' + $('#updateFormID').serialize();
            $("#subBtn").attr("disabled",true);
            $.ajax({
                type:'post',
                url:'/user/updateStaff',
                data:data,
                cache:false,
            }).done(
                function(res) {
                    if (res > 0) {
                        layer.msg('更新成功',{icon:6})
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function() {
                    layer.msg('新增失败',{icon:5})
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        })



    });
</script>
</body>

</html>
